package com.sansan.ultrasound_handpad.base;

import android.os.Environment;

import com.tencent.mmkv.MMKV;

import java.io.File;

/**
 * 存儲值
 */
public class MmkvManager {

    private static final String APKCACHE_DIRECTORY =
            Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "MMKV";
    private MMKV mMMKV = null;

    public static MmkvManager getInstance() {
        return MmkvManagerHandler.ourInstance;
    }

    private MmkvManager() {}

    public void init() {
        // 初始化MMKV的路径
//        FileUtils.createOrExistsDir(APKCACHE_DIRECTORY + File.separator + "MMKVCache");
        if (mMMKV == null) {
            // 设置缓存文件夹
            MMKV.initialize(APKCACHE_DIRECTORY);
            mMMKV = MMKV.mmkvWithID("SANSANUPDATE", MMKV.MULTI_PROCESS_MODE);
        }
    }

    public MMKV getMMKV() {
        if (mMMKV == null) {
            // 设置缓存文件夹
//            MMKV.initialize(APKCACHE_DIRECTORY + File.separator + "MMKVCache");
            MMKV.initialize(APKCACHE_DIRECTORY);
            mMMKV = MMKV.mmkvWithID("SANSANUPDATE", MMKV.MULTI_PROCESS_MODE);
        }

        return mMMKV;
    }

    private static class MmkvManagerHandler {
        private static final MmkvManager ourInstance = new MmkvManager();
    }
}
